﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;
using System.Dynamic;
using FluorineFx.Json;

namespace lxwmvc
{
    public static partial class huifucontroller
    {

        /// <summary>

        /// </summary>
        /// <param name="pb"></param>
        //public static void huifu_chongzhi(pagebase pb)
        //{
            
        //}
        /// <summary>
        /// 商户给用户打钱
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="jine"></param>
        public static void huifu_shanghu_tuihuan(string userid, decimal jine)
        {            
            supermodel has = core_user.getUserInfo(userid);

            Transfer objsend = new Transfer();
            objsend.CmdId = "Transfer";
            objsend.OutCustId = HuiFuArg.MerCustId;
            //objsend.OrdId = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            objsend.OutAcctId = HuiFuArg.AcctId;
            objsend.InCustId = has["UsrCustId"].tostr();
            objsend.InAcctId = HuiFuArg.AcctId;
            objsend.TransAmt = jine.tostr();
            objsend.BgRetUrl = HuiFuArg.LocalUrl + "huifu/huifu_shanghu_tuihuan_returnbg";
            objsend.RetUrl = "";

            supermodel data = supermodel.create("Mpaymoney");
            //todo.start 补充完整里面的信息
            data["LogType"] = 0;
            data["SetupDate"] = DateTime.Now;
            data["OutCustId"] = objsend.OutCustId;
            data["OrdId"] = objsend.OrdId;
            data["OutAcctId"] = objsend.OutAcctId + "";
            data["TransAmt"] = objsend.TransAmt + "";
            data["InCustId"] = objsend.InCustId + "";
            data["InAcctId"] = objsend.InAcctId + "";
            var ret = data.saveorupdate();
            objsend.MerPriv = ret.identity + "";

            var r = core_huifu.Send<RetTransfer>(objsend);
            if (r.RespCode == core_huifu.HUIFU_SUCCESS)
            {
                var Mpaymoney = supermodel.create("Mpaymoney");
                Mpaymoney["Mpaymoneyid"] = objsend.MerPriv;
                Mpaymoney["logtype"] = "1";
                //更新信息
                Mpaymoney.saveorupdate();
            }
        }
    }
}